﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace _1stVATCWin
{
    public partial class Home : Form
    {
        private string userName;
        public Home(string userName)
        {
            InitializeComponent();
            this.userName = userName;
        }
        private void button2_Click(object sender, EventArgs e)
        {
            Information fr = new Information(userName);
            fr.TopLevel = false;
            fr.Dock = DockStyle.Fill;
            fr.Visible = true;
            fr.FormBorderStyle = FormBorderStyle.None;
            panelHome.Controls.Add(fr);
        }
        private void load_Home()
        {
            Config file = new Config(Application.StartupPath + "\\config.ini");
            String connectionstring = file.ReadValue("Server", "conn"); // doc gia tri trong file config.ini tai truong [server], gia tri muon doc la con
            SqlConnection conn = new SqlConnection(connectionstring);
            string sql = "select IDnhanvien,hoten,tenchucvu from NHANVIEN join CHUCVU ON NHANVIEN.IDchucvu = CHUCVU.IDchucvu where IDnhanvien = @IDnhanvien";
            SqlCommand cmd = new SqlCommand(sql, conn);
            cmd.Parameters.AddWithValue("@IDnhanvien", userName);
            conn.Open();
            SqlDataReader reader = cmd.ExecuteReader();
            if(reader.Read())
            {
                labelFullname.Text = (string) reader["hoten"];
                labelIDPosition.Text = (string) reader["tenchucvu"];
                reader.Close();
            }
            cmd.ExecuteNonQuery();
            conn.Close();
        }

        private void Home_Load(object sender, EventArgs e)
        {
            load_Home();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
